package test;

import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.io.IOException;

public class q extends JFrame {
    SpringLayout springLayout=new SpringLayout();
    JPanel LeftPanel=new JPanel();
    JPanel RightUpPanel=new JPanel();
    public JScrollPane jScrollPane=new JScrollPane();

    public Border border1= BorderFactory.createLineBorder(Color.RED, 2);
    public Border border2= BorderFactory.createLineBorder(Color.BLUE, 2);
    public Border border3= BorderFactory.createLineBorder(Color.CYAN, 2);

    public q(){
        super("测试边界布局");
        Container contentPane=getContentPane();
        //设置布局管理器
        contentPane.setLayout(springLayout);


        LeftPanel.setBorder(border1);
        RightUpPanel.setBorder(border2);
        jScrollPane.setBorder(border3);

        LeftPanel.setPreferredSize(new Dimension(100, 400));
        RightUpPanel.setPreferredSize(new Dimension(500, 40));
        jScrollPane.getViewport().setPreferredSize(new Dimension(500, 560));

        //
        springLayout.putConstraint(SpringLayout.WEST,LeftPanel,0,SpringLayout.WEST,contentPane);
        springLayout.putConstraint(SpringLayout.NORTH,LeftPanel,0,SpringLayout.NORTH,contentPane);

        springLayout.putConstraint(SpringLayout.WEST,RightUpPanel,0,SpringLayout.EAST,LeftPanel);
        springLayout.putConstraint(SpringLayout.NORTH,RightUpPanel,0,SpringLayout.NORTH,LeftPanel);

        springLayout.putConstraint(SpringLayout.EAST,jScrollPane,0,SpringLayout.EAST,contentPane);
        springLayout.putConstraint(SpringLayout.SOUTH,jScrollPane,0,SpringLayout.SOUTH,contentPane);

        contentPane.add(LeftPanel);
        contentPane.add(RightUpPanel);
        contentPane.add(jScrollPane);

        int width=600;
        int height=400;
        setSize(width,height);//单位：像素px
        //居中
        setLocationRelativeTo(null);
        //关闭程序时自动退出程序
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //固定页面大小
        setResizable(false);
        setVisible(true);
    }
    public static void main(String[] args) throws IOException {
        new q();
    }
}